package nio;

import java.nio.IntBuffer;
import java.util.Arrays;

/**
 * @Author Klys
 * @Date 2023/6/3 11:35
 * @Description
 * @Version 1.0
 */
public class Demo10 {

    //压缩缓冲区

    public static void main(String[] args) {
        IntBuffer buffer = IntBuffer.wrap(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 0});
        for (int i = 0; i < 4; i++) buffer.get();   //先正常读4个
        buffer.compact();   //压缩缓冲区

        System.out.println("压缩之后的情况：" + Arrays.toString(buffer.array()));
        System.out.println("当前position位置：" + buffer.position());
        System.out.println("当前limit位置：" + buffer.limit());
    }
}
